//<feature charts>
Ext.define('AkData.view.RekabetDagilimi', {
    extend: 'Ext.Panel',
    requires: ['Ext.chart.Chart', 'Ext.chart.interactions.PanZoom', 'Ext.chart.series.Bar', 'Ext.chart.axis.Numeric', 'Ext.chart.axis.Category', 'Ext.carousel.Carousel'],
    config: {
		layout: 'fit',
		
        items: [
            {
                xtype: 'toolbar',
				docked: 'top',
				/*
				cls: 'charttoolbar',
				top: 0,
                right: 0,
                zIndex: 50,
				*/
				items: [
                    {
                        iconCls: 'refresh',
						style: {'background': '#E8E8E8', 'color': 'black'},
                        handler: function () {
							Ext.Viewport.mask({xtype: 'loadmask', message: _lang_Yukleniyor});
							Ext.getStore('RekabetDagilimi_Store').load(function(records, operation, success) {Ext.Viewport.unmask();}, this);
                        }
                    },
				]
            },
			{
				flex: 1,
                xtype: 'chart',
                store: 'RekabetDagilimi_Store',
                background: 'white',
				hidden: true,
				id: 'RekabetDagilimi_ID',
                colors: AkData.view.ColorPatterns.getAlteredBaseColorsHSL({s: -0.1}),
				flipXY: true,
				innerPadding: {right: 20},
                series: [
                    {
                        type: 'bar',
                        xField: 'baslik',
                        yField: ['deger'],
						title: ['Değer'],
                        //stacked: false,
						style: {maxBarWidth: 10},
						/*
						label: {
							display: 'outside',  orientation: 'horizontal',
							field: ['deger'],
						},
						*/
						renderer: function(sprite, config, rendererData, index) {
							//console.log('Gerçek: ' + config.x);
                            var store = rendererData.store,
                                storeItems = store.getData().items,
                                record = storeItems[index],
                                surface = sprite.getParent(),
                                textSprites, textSprite, rectSprite;
								
                            if (!record) {
                                return;
                            }
							
							textSprites = surface.myTextSprites1;
							if (!textSprites) {
								textSprites = surface.myTextSprites1 = [];
							}
							textSprite = textSprites[index];
							if (!textSprite) {
								textSprite = textSprites[index] = surface.add({type:'text'});
								rectSprite = textSprite.rectSprite = surface.add({type:'rect'});
							} else {
								rectSprite = textSprite.rectSprite;
								textSprite.show();
								rectSprite.show();
							}
							
							textSprite.setAttributes({text: numberformat(record.data['deger']), x: config.x - 1, y: config.y + 10, fill: 'black', fontSize: 12, fontWeight: 'bold', zIndex: 10001, 
							
							scalingY: 1, scalingX: 1, translationX: 1, translationY: 1, rotationCenterX: -100 , rotationCenterY: 0,
							
							});
							
							return null;
                        },
                    }
                ],
				
				interactions: [{type: 'panzoom'}],
				
                axes: [
                    {
                        type: 'numeric',
                        position: 'bottom',
                        fields: 'deger',
						grid: true,
                    },
                    {
                        type: 'category',
                        position: 'left',
                        fields: 'baslik',
						label: {fontSize: 9},
						grid: true,
                    }
                ]
            },
        ]
    },
	
    initialize: function () {
		this.callParent();
		
		var task = Ext.create('Ext.util.DelayedTask', function() {
			Ext.Viewport.mask({xtype: 'loadmask', message: _lang_Yukleniyor});
			Ext.getStore('RekabetDagilimi_Store').load(function(records, operation, success) {
				Ext.Viewport.unmask();
				
				Ext.getCmp('RekabetDagilimi_ID').setHidden(false);
			}, this);
		}, this);

		task.delay(500);
    }
	
});
//</feature>
